package com.csdj.t309tgspringboot.service;

import com.csdj.t309tgspringboot.entity.User;
import com.csdj.t309tgspringboot.entity.UserExample;
import com.csdj.t309tgspringboot.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("iUserService")
public class UserService implements IUserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public int registerUser(User user) {
        UserExample userExample = new UserExample();
        userExample.createCriteria();
        int num = userMapper.insert(user);
        return num;
    }

    @Override
    public User login(String account,String pass) {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andAccountEqualTo(account).andPasswordEqualTo(pass);
        User user = userMapper.selectByExample(userExample).get(0);
        return user;
    }

    @Override
    public List<User> selUser() {
        UserExample userExample = new UserExample();
        userExample.createCriteria();
        List<User> user = userMapper.selectByExample(userExample);
        return user;
    }

    @Override
    public User selUsera(Integer userId) {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andIdEqualTo(userId);
        User user = userMapper.selectByExample(userExample).get(0);
        return user;
    }
}
